<?php

namespace app\admin\controller;

use app\admin\model\User;
use think\Controller;
use think\Request;
use think\Session;
use think\Loader;

class Login extends Controller
{
    public function index()
    {
        if( Session::has('userInfo') ) {
            $this->redirect('admin/Index/index');
        }
        return view();
    }

    public function doLogin()
    {
        if(request()->isAjax() ) {
            $user = new User();
            $login = $user->login(input('username'),input('password'));
            if($login == 0){
                $this->error('用户名或密码错误！');
            }else{
                Session::set('userInfo', $login);
                $this->success('登录成功，正在跳转！','Index/index');
            }
        }else{
            $this->error( '请求无效');
        }


    }

    public function out(){
        Session::delete('userInfo');
        $this->success('注销成功！','admin/Login/index');

    }
}
